package eu.dominicum.ft.pd;

/**
 * A score in the Fantasy Tour.
 *
 * @author Harry Klerks
 * @since 2013M1
 */
public class FantasyScore extends PersistentDomainObject {

    /**
     * The participant who has earned this scores.
     */
    private Participant participant;

    /**
     * The fantasy team member that earned this score.
     */
    private FantasyTeamMember fantasyTeamMember;

    /**
     * Points earned in this score.
     */
    private Integer pointsEarned;

    /**
     * The stage result detail for which this score is earned.
     */
    private StageResultDetail stageResultDetail;

    /**
     * The fantasy stage for which this score is earned.
     */
    private FantasyStage fantasyStage;

    /**
     * .
     *
     * @return Participant
     */
    public final Participant getParticipant() {
        return participant;
    }

    /**
     * .
     *
     * @return FantasyTeamMember
     */
    public final FantasyTeamMember getFantasyTeamMember() {
        return fantasyTeamMember;
    }

    /**
     * .
     *
     * @return Integer
     */
    public final Integer getPointsEarned() {
        return pointsEarned;
    }

    /**
     * .
     *
     * @return StageResultDetail
     */
    public final StageResultDetail getStageResultDetail() {
        return stageResultDetail;
    }

    /**
     * Calculate a FantasyScore object for the given configuration, team member, particpant and stage result detail.
     *
     * @param fantasyTourConfiguration -
     * @param fantasyTeamMember        -
     * @param participant              -
     * @param stageResultDetail        -
     * @param fantasyStage             -
     * @return FantasyScore
     */
    public static FantasyScore calculate(final FantasyTourConfiguration fantasyTourConfiguration,
                                         final FantasyTeamMember fantasyTeamMember,
                                         final Participant participant,
                                         final StageResultDetail stageResultDetail,
                                         final FantasyStage fantasyStage) {
        FantasyScore newFantasyScore = new FantasyScore();

        newFantasyScore.participant = participant;
        newFantasyScore.fantasyTeamMember = fantasyTeamMember;
        newFantasyScore.stageResultDetail = stageResultDetail;
        newFantasyScore.fantasyStage = fantasyStage;
        switch (stageResultDetail.getStageResult().getResultType()) {
            case OVERALL:
                newFantasyScore.pointsEarned =
                        fantasyTourConfiguration.getRidersInListCount() - fantasyTeamMember.getRank() + 1;
                break;
            case POINTS:
                newFantasyScore.pointsEarned = stageResultDetail.getPoints();
                break;
            case CLIMBING:
                newFantasyScore.pointsEarned = stageResultDetail.getPoints();
                break;
            case YOUTH:
                newFantasyScore.pointsEarned =
                        fantasyTourConfiguration.getRidersInListCount() - fantasyTeamMember.getRank() + 1;
                break;
            default:
                newFantasyScore.pointsEarned = 0;
        }
        return newFantasyScore;
    }

    /**
     * .
     *
     * @return FantasyScore
     */
    public final FantasyStage getFantasyStage() {
        return fantasyStage;
    }
}
